package com.huluobo.document

import com.huluobo.lib_base.BaseViewModel
import com.huluobo.lib_base.HttpType
import com.huluobo.lib_base.Res
import com.huluobo.lib_base.UIIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
 *  Created by LC on 2025/3/27.
 */
@HiltViewModel
class DocumentViewModel @Inject constructor(private val documentRepo: DocumentRepo) : BaseViewModel<DocumentIntent>() {
    override fun handleIntent(it: UIIntent) {
        when (it) {
            is DocumentIntent.GetDocument -> {
                httpRequest(documentRepo.getDocuments() as Flow<Res<Any>>)
            }

            is DocumentIntent.ScanFiles -> {
                scanFile(it.file)
            }

            is DocumentIntent.UploadDocument -> {
                httpRequest(documentRepo.uploadDocument(it.name, it.path), HttpType.UPLOAD)
            }

            is DocumentIntent.DeleteDocument -> {
                httpRequest(documentRepo.deleteDocument(it.id), HttpType.DELETE)
            }
        }
    }
}